package com.chinacoal.microservice.impl.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.chinacoal.microservice.api.*;
import com.chinacoal.microservice.api.model.ForeignTaskParam;
import com.chinacoal.microservice.api.model.resource.*;
import com.chinacoal.microservice.impl.service.CcmsTaskService;
import com.chinacoal.microservice.model.affair.vo.*;
import com.chinacoal.microservice.model.wofkflow.entity.ApprovalHistoryEntity;
import com.chinacoal.microservice.util.result.CodeMsg;
import com.chinacoal.microservice.util.result.Result;
import com.chinacoal.microservice.util.tool.DateTools;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 协同指挥平台的待办集成处理实现类
 * @author linp
 * @date 2020年5月9日 下午5:22:56
 * @version V1.0
 */
@Service
public class CcmsTaskServiceIml implements CcmsTaskService {

	 @Resource
	 private 	CcmsHrBizAwayClient  ccmsHrBizAwayClient;


	@Resource
	private CcmsPartySealClient ccmsPartySealClient;

	@Resource
	private CcmsHrEmpDimissionClient ccmsHrEmpDimissionClient;

	@Resource
	private CcmsImEmpFaClient ccmsImEmpFaClient;

	@Resource
	private CcmsHrLeaveClient ccmsHrLeaveClient;


	@Resource
	private  CcmsOfficialSealClient  ccmsOfficialSealClient;

	@Resource
	private CcmsBizReceiveClient ccmsBizReceiveClient;

	@Resource
	private CcmsRentCarClient ccmsRentCarClient;

	@Resource
	private CcmsHrSepClient ccmsHrSepClient;

	@Resource
	private CcmsEmpTrainClient ccmsEmpTrainClient;

	 @Resource
	 private WorkflowClient  workflowClient;

	@Override
	public Result<BusinessData> getDetails(ForeignTaskParam foreignTaskParam) throws Exception {
		 String bizCode = foreignTaskParam.getBizCode();
		Result<BusinessData> businessData=null;
		 //申请单类型 -- 因公外出申请单
		 if(StringUtils.equalsIgnoreCase(bizCode, UnionTaskVar.APP_FORM_TYPE_01)){
			 businessData = this.buildHrBizAwayData(foreignTaskParam);
		 }else if(StringUtils.equalsIgnoreCase(bizCode, UnionTaskVar.APP_FORM_TYPE_02)){
		 //申请单类型 -- 党章申请单
			businessData = this.buildPartySealData(foreignTaskParam);
		 }else if(StringUtils.equalsIgnoreCase(bizCode, UnionTaskVar.APP_FORM_TYPE_03)){
			//申请单类型 -- 离职申请单
			businessData = this.buildHrEmpDimissionData(foreignTaskParam);
		}else if(StringUtils.equalsIgnoreCase(bizCode, UnionTaskVar.APP_FORM_TYPE_04)){
			 //申请单类型 -- 固定资产申请单
			 businessData = this.buildImEmpFaData(foreignTaskParam);
		 }else if(StringUtils.equalsIgnoreCase(bizCode, UnionTaskVar.APP_FORM_TYPE_05)){
			 //申请单类型 --请假申请单
			 businessData = this.buildHrLeaveData(foreignTaskParam);
		 }else if(StringUtils.equalsIgnoreCase(bizCode, UnionTaskVar.APP_FORM_TYPE_06)){
			 //申请单类型 --公章申请单
			 businessData = this.buildOfficialSealData(foreignTaskParam);
		 }else if(StringUtils.equalsIgnoreCase(bizCode, UnionTaskVar.APP_FORM_TYPE_07)){
			 //申请单类型 -- 培训需求申请单
			 businessData = this.buildEmpTrainData(foreignTaskParam);
		 }else if(StringUtils.equalsIgnoreCase(bizCode, UnionTaskVar.APP_FORM_TYPE_08)){
			 //申请单类型 -- 业务招待申请单
			 businessData = this.buildBizReceiveData(foreignTaskParam);
		 }else if(StringUtils.equalsIgnoreCase(bizCode, UnionTaskVar.APP_FORM_TYPE_09)){
			 //申请单类型 -- 外埠租车申请单
			 businessData = this.buildRentCarData(foreignTaskParam);
		 }else if(StringUtils.equalsIgnoreCase(bizCode, UnionTaskVar.APP_FORM_TYPE_10)){
			 //申请单类型 -- 外部专家聘用申请单
			 businessData = this.buildHrSepEmpData(foreignTaskParam);
		 }


		return  businessData;
	}

	/**
	 * 构建  外部专家聘用申请单 详情
	 * @param foreignTaskParam
	 * @return
	 */
	private Result<BusinessData> buildHrSepEmpData(ForeignTaskParam foreignTaskParam)throws Exception {
		Result<CcmsHrSepVO> inforResult = ccmsHrSepClient.selectDetail(foreignTaskParam.getBusinessId());
		if(inforResult.getCode() != 10000){
			return  Result.error(CodeMsg.SERVER_ERROR.fillArgs("调用外部专家聘用申请单服务端异常： "+inforResult.getMsg()));
		}
		if( null == inforResult.getData() ){
			return  Result.error(CodeMsg.NOT_FOUND);
		}
		//封装数据对象
		BusinessData businessData = new BusinessData();
		CcmsHrSepVO info = inforResult.getData();
		// 基础信息
		FormCanvasData business  = new FormCanvasData();
		business.setName("外部专家聘用申请单");
		business.add("组织",info.getOrgName());
		business.add("实际申请人",info.getEmpName());
		business.add("专家姓名",info.getSepEmployeeName());
		business.add("开始日期", DateTools.dateToString( info.getStartDate(),"yyyy-MM-dd"));
		business.add("结束日期", DateTools.dateToString( info.getEndDate(),"yyyy-MM-dd"));
		business.add("单价（元/人/天）",info.getPrice()== null ? "" : info.getPrice()+"");
		business.add("预计天数",info.getDays() == null ? "" : info.getDays()+"");
		business.add("预估费用",info.getTotalAmt()== null ? "" : info.getTotalAmt()+"");
		business.add("项目",info.getProjectNo());
		business.add("提供单位",info.getSepVendorName());
		business.add("聘用事由",info.getApplyDesc());
		businessData.addFormCanvasData(business);
		/**
		 * 相关附件  暂未实现
		 */
		TableCanvasData fileInfo = new TableCanvasData();
		fileInfo.setName("附件列表");
		businessData.setFileInfo(fileInfo);

		// 获取审核信息
		Result<Page<ApprovalHistoryEntity>> historyInfoResult = workflowClient.getApprovalHistory(0, Integer.MAX_VALUE, Long.valueOf(info.getProcessInstId()));
		if(historyInfoResult.getCode() != 10000){
			return  Result.error(CodeMsg.SERVER_ERROR.fillArgs("调用工作流获取审批历史服务端异常： "+historyInfoResult.getMsg()));
		}
		//封装审核信息
		this.buildApprovalRecords(businessData,historyInfoResult);

		// 封装审核按钮
		this.buildButtonInfo(businessData);

		// 返回信息
		DictionaryCanvasData resultInfo = new DictionaryCanvasData();
		businessData.setResultInfo(resultInfo);

		return Result.success(businessData);
	}

	/**
	 * 构建  外埠租车申请单 详情
	 * @param foreignTaskParam
	 * @return
	 */
	private Result<BusinessData> buildRentCarData(ForeignTaskParam foreignTaskParam)throws Exception {
		Result<CcmsRentCarVO> inforResult = ccmsRentCarClient.selectDetail(foreignTaskParam.getBusinessId());
		if(inforResult.getCode() != 10000){
			return  Result.error(CodeMsg.SERVER_ERROR.fillArgs("调用外埠租车申请单服务端异常： "+inforResult.getMsg()));
		}
		if( null == inforResult.getData() ){
			return  Result.error(CodeMsg.NOT_FOUND);
		}
		//封装数据对象
		BusinessData businessData = new BusinessData();
		CcmsRentCarVO info = inforResult.getData();
		// 基础信息
		FormCanvasData business  = new FormCanvasData();
		business.setName("外埠租车申请单");
		business.add("组织",info.getOrgName());
		business.add("用车地点",info.getRentCarPos());
		business.add("用车时间",DateTools.dateToString(info.getStartDate(),"yyyy-MM-dd"));
		business.add("返回时间", DateTools.dateToString(info.getEndDate() ,"yyyy-MM-dd"));
		business.add("申请日期",DateTools.dateToString(info.getCreationDate() ,"yyyy-MM-dd"));
		business.add("项目",info.getProjectNo());
		business.add("用车事由",info.getRentCarDesc());
		businessData.addFormCanvasData(business);
		/**
		 * 相关附件  暂未实现
		 */
		TableCanvasData fileInfo = new TableCanvasData();
		fileInfo.setName("附件列表");
		businessData.setFileInfo(fileInfo);

		// 获取审核信息
		Result<Page<ApprovalHistoryEntity>> historyInfoResult = workflowClient.getApprovalHistory(0, Integer.MAX_VALUE, Long.valueOf(info.getProcessInstId()));
		if(historyInfoResult.getCode() != 10000){
			return  Result.error(CodeMsg.SERVER_ERROR.fillArgs("调用工作流获取审批历史服务端异常： "+historyInfoResult.getMsg()));
		}
		//封装审核信息
		this.buildApprovalRecords(businessData,historyInfoResult);

		// 封装审核按钮
		this.buildButtonInfo(businessData);

		// 返回信息
		DictionaryCanvasData resultInfo = new DictionaryCanvasData();
		businessData.setResultInfo(resultInfo);

		return Result.success(businessData);
	}

	/**
	 * 构建  业务招待申请单 详情
	 * @param foreignTaskParam
	 * @return
	 */
	private Result<BusinessData> buildBizReceiveData(ForeignTaskParam foreignTaskParam)throws Exception {
		Result<CcmsBizReceiveVO> inforResult = ccmsBizReceiveClient.selectDetail(foreignTaskParam.getBusinessId());
		if(inforResult.getCode() != 10000){
			return  Result.error(CodeMsg.SERVER_ERROR.fillArgs("调用业务招待申请单服务端异常： "+inforResult.getMsg()));
		}
		if( null == inforResult.getData() ){
			return  Result.error(CodeMsg.NOT_FOUND);
		}
		//封装数据对象
		BusinessData businessData = new BusinessData();
		CcmsBizReceiveVO info = inforResult.getData();
		// 基础信息
		FormCanvasData business  = new FormCanvasData();
		business.setName("业务招待申请单");
		business.add("组织",info.getOrgName());
		business.add("来访日期", DateTools.dateToString(info.getServeDate(),"yyyy-MM-dd"));
		business.add("来访人数",info.getVisitors()== null ? "" : info.getVisitors()+"");
		business.add("申请日期", DateTools.dateToString(info.getCreationDate() ,"yyyy-MM-dd"));
		business.add("来访单位",info.getVisitCompany());
		business.add("招待事由",info.getServeDesc());
		business.add("用餐地点",info.getServePos());
		business.add("拟陪同人数",info.getEscorts() == null ? "" : info.getEscorts()+"");
		business.add("用餐标准（元/人）",info.getExStd()== null ? "" : info.getExStd()+"");
		business.add("用餐预估费用（元)",info.getExTotalAmt() == null ? "" : info.getExTotalAmt()+"");
		business.add("住宿地点",info.getHotelPos());
		business.add("住宿天数:",info.getDays()== null ? "" : info.getDays()+"");
		business.add("住宿标准（元/人）",info.getHotelStd() == null ? "" : info.getHotelStd()+"");
		business.add("住宿预估费用（元）",info.getHotelAmt() == null ? "" : info.getHotelAmt()+"");
		businessData.addFormCanvasData(business);
		/**
		 * 相关附件  暂未实现
		 */
		TableCanvasData fileInfo = new TableCanvasData();
		fileInfo.setName("附件列表");
		businessData.setFileInfo(fileInfo);

		// 获取审核信息
		Result<Page<ApprovalHistoryEntity>> historyInfoResult = workflowClient.getApprovalHistory(0, Integer.MAX_VALUE, Long.valueOf(info.getProcessInstId()));
		if(historyInfoResult.getCode() != 10000){
			return  Result.error(CodeMsg.SERVER_ERROR.fillArgs("调用工作流获取审批历史服务端异常： "+historyInfoResult.getMsg()));
		}
		//封装审核信息
		this.buildApprovalRecords(businessData,historyInfoResult);

		// 封装审核按钮
		this.buildButtonInfo(businessData);

		// 返回信息
		DictionaryCanvasData resultInfo = new DictionaryCanvasData();
		businessData.setResultInfo(resultInfo);

		return Result.success(businessData);
	}

	/**
	 * 构建  培训需求申请单 详情
	 * @param foreignTaskParam
	 * @return
	 */
	private Result<BusinessData> buildEmpTrainData(ForeignTaskParam foreignTaskParam)throws Exception {
		Result<CcmsEmpTrainVO> inforResult = ccmsEmpTrainClient.selectDetail(foreignTaskParam.getBusinessId());
		if(inforResult.getCode() != 10000){
			return  Result.error(CodeMsg.SERVER_ERROR.fillArgs("调用培训需求申请单服务端异常： "+inforResult.getMsg()));
		}
		if( null == inforResult.getData() ){
			return  Result.error(CodeMsg.NOT_FOUND);
		}
		//封装数据对象
		BusinessData businessData = new BusinessData();
		CcmsEmpTrainVO info = inforResult.getData();
		// 基础信息
		FormCanvasData business  = new FormCanvasData();
		business.setName("培训需求申请单");
		business.add("组织",info.getOrgName());
		business.add("申请人",info.getEmpName());
		business.add("开始日期",  DateTools.dateToString( info.getStartDate() ,"yyyy-MM-dd"));
		business.add("结束日期",  DateTools.dateToString( info.getEndDate() ,"yyyy-MM-dd"));
		business.add("申请日期", DateTools.dateToString(info.getCreationDate() ,"yyyy-MM-dd"));
		business.add("培训方式",info.getTrainTypeName());
		business.add("参与人数",info.getMembers() == null ? "" : info.getMembers()+"");
		business.add("培训费用(元)",info.getAmount() == null ? "" : info.getAmount()+"");
		business.add("培训内容",info.getTrainContent());
		business.add("培训目的",info.getTrainGoal());
		businessData.addFormCanvasData(business);
		/**
		 * 相关附件  暂未实现
		 */
		TableCanvasData fileInfo = new TableCanvasData();
		fileInfo.setName("附件列表");
		businessData.setFileInfo(fileInfo);

		// 获取审核信息
		Result<Page<ApprovalHistoryEntity>> historyInfoResult = workflowClient.getApprovalHistory(0, Integer.MAX_VALUE, Long.valueOf(info.getProcessInstId()));
		if(historyInfoResult.getCode() != 10000){
			return  Result.error(CodeMsg.SERVER_ERROR.fillArgs("调用工作流获取审批历史服务端异常： "+historyInfoResult.getMsg()));
		}
		//封装审核信息
		this.buildApprovalRecords(businessData,historyInfoResult);

		// 封装审核按钮
		this.buildButtonInfo(businessData);

		// 返回信息
		DictionaryCanvasData resultInfo = new DictionaryCanvasData();
		businessData.setResultInfo(resultInfo);

		return Result.success(businessData);
	}


	/**
	 *  构建 公章申请单  详情
	 * @param foreignTaskParam
	 * @return
	 */
	private Result<BusinessData> buildOfficialSealData(ForeignTaskParam foreignTaskParam) throws Exception{
		Result<CcmsOfficeSealVO> inforResult = ccmsOfficialSealClient.selectDetail(foreignTaskParam.getBusinessId());
		if(inforResult.getCode() != 10000){
			return  Result.error(CodeMsg.SERVER_ERROR.fillArgs("调用公章申请单服务端异常： "+inforResult.getMsg()));
		}
		if( null == inforResult.getData() ){
			return  Result.error(CodeMsg.NOT_FOUND);
		}
		//封装数据对象
		BusinessData businessData = new BusinessData();
		CcmsOfficeSealVO info = inforResult.getData();
		// 基础信息
		FormCanvasData business  = new FormCanvasData();
		business.setName("公章申请单");
		business.add("组织",info.getOrgName());
		business.add("申请人",info.getEmpName());
		business.add("申请日期", DateTools.dateToString(info.getCreationDate()  ,"yyyy-MM-dd"));
		/**
		 * 类型
		 */
		String officialType="";
		//公章
		String official = info.getOfficial();
		if(StringUtils.isNotBlank(official) && StringUtils.equalsIgnoreCase(official,"y")){
			officialType+="公章&nbsp;";
		}
		//法人章
		String corporate = info.getCorporate();
		if(StringUtils.isNotBlank(corporate) && StringUtils.equalsIgnoreCase(corporate,"y")){
			officialType+="法人章&nbsp;";
		}
		//合同章
		String contract = info.getContract();
		if(StringUtils.isNotBlank(contract) && StringUtils.equalsIgnoreCase(contract,"y")){
			officialType+="合同章";
		}
		business.add("类型",officialType);
		business.add("申请编码",info.getOfficialSealCode());
		business.add("公章次数",info.getOfficialSealNum()== null ? "" : info.getOfficialSealNum()+"");
		business.add("法人章次数",info.getCorporateCharterNum() == null ? "" : info.getCorporateCharterNum()+"");
		business.add("合同章次数",info.getContractSealNum() == null ? "" : info.getContractSealNum()+"");
		business.add("用途",info.getOfficialDesc());
		businessData.addFormCanvasData(business);
		/**
		 * 相关附件  暂未实现
		 */
		TableCanvasData fileInfo = new TableCanvasData();
		fileInfo.setName("附件列表");
		businessData.setFileInfo(fileInfo);

		// 获取审核信息
		Result<Page<ApprovalHistoryEntity>> historyInfoResult = workflowClient.getApprovalHistory(0, Integer.MAX_VALUE, Long.valueOf(info.getProcessInstId()));
		if(historyInfoResult.getCode() != 10000){
			return  Result.error(CodeMsg.SERVER_ERROR.fillArgs("调用工作流获取审批历史服务端异常： "+historyInfoResult.getMsg()));
		}
		//封装审核信息
		this.buildApprovalRecords(businessData,historyInfoResult);

		// 封装审核按钮
		this.buildButtonInfo(businessData);

		// 返回信息
		DictionaryCanvasData resultInfo = new DictionaryCanvasData();
		businessData.setResultInfo(resultInfo);

		return Result.success(businessData);
	}



	/**
	 *  构建 请假申请单  详情
	 * @param foreignTaskParam
	 * @return
	 */
	private Result<BusinessData> buildHrLeaveData(ForeignTaskParam foreignTaskParam)throws Exception{
		Result<CcmsHrLeaveVO> inforResult = ccmsHrLeaveClient.selectDetail(foreignTaskParam.getBusinessId());
		if(inforResult.getCode() != 10000){
			return  Result.error(CodeMsg.SERVER_ERROR.fillArgs("调用请假申请单服务端异常： "+inforResult.getMsg()));
		}
		if( null == inforResult.getData() ){
			return  Result.error(CodeMsg.NOT_FOUND);
		}
		//封装数据对象
		BusinessData businessData = new BusinessData();
		CcmsHrLeaveVO info = inforResult.getData();

		// 基础信息
		FormCanvasData business  = new FormCanvasData();
		business.setName("请假申请单");
		business.add("组织",info.getOrgName());
		business.add("假期类型",info.getHolidayTypeName());
		business.add("工龄",info.getWorkYear()== null ? "" : info.getWorkYear()+"");
		business.add("开始日期", DateTools.dateToString(info.getStartDate() ,"yyyy-MM-dd HH:mm:ss"));
		business.add("结束日期",DateTools.dateToString(info.getEndDate() ,"yyyy-MM-dd HH:mm:ss"));
		business.add("请假天数",info.getDays()== null ? "" : info.getDays()+"");
		business.add("联系电话",info.getTelephone());
		business.add("紧急联系人",info.getContact());
		business.add("紧急联系人电话",info.getContactPhone());
		business.add("去向",info.getPosition());
		//business.add("员工类型",info.get);
		business.add("申请单编号",info.getApplyCode());
		String  isLeavePeking ="";
		if(StringUtils.isNotBlank(info.getIsLeavePeking())){
			if(StringUtils.equalsIgnoreCase("Y",info.getIsLeavePeking())){
				isLeavePeking="是";
			}else if(StringUtils.equalsIgnoreCase("N",info.getIsLeavePeking())){
				isLeavePeking="否";
			}
		}
		business.add("是否离京",isLeavePeking);
		business.add("离京时间",  DateTools.dateToString(info.getLeavePekingTime(),"yyyy-MM-dd HH:mm:ss"));
		business.add("回京时间",  DateTools.dateToString(info.getBackPekingTime(),"yyyy-MM-dd HH:mm:ss"));
		business.add("申请日期",  DateTools.dateToString(info.getCreationDate(),"yyyy-MM-dd HH:mm:ss"));
		business.add("请假事由",info.getApplyDesc());
		businessData.addFormCanvasData(business);
		/**
		 * 相关附件  暂未实现
		 */
		TableCanvasData fileInfo = new TableCanvasData();
		fileInfo.setName("附件列表");
		businessData.setFileInfo(fileInfo);

		// 获取审核信息
		Result<Page<ApprovalHistoryEntity>> historyInfoResult = workflowClient.getApprovalHistory(0, Integer.MAX_VALUE, Long.valueOf(info.getProcessInstId()));
		if(historyInfoResult.getCode() != 10000){
			return  Result.error(CodeMsg.SERVER_ERROR.fillArgs("调用工作流获取审批历史服务端异常： "+historyInfoResult.getMsg()));
		}
		//封装审核信息
		this.buildApprovalRecords(businessData,historyInfoResult);

		// 封装审核按钮
		this.buildButtonInfo(businessData);

		// 返回信息
		DictionaryCanvasData resultInfo = new DictionaryCanvasData();
		businessData.setResultInfo(resultInfo);

		return Result.success(businessData);
	}

	/**
	 * 构建 党章申请单 详情
	 * @param foreignTaskParam
	 * @return
	 */
	private Result<BusinessData> buildPartySealData(ForeignTaskParam foreignTaskParam)throws Exception  {
		Result<CcmsPartySealVO> inforResult = ccmsPartySealClient.selectDetail(foreignTaskParam.getBusinessId());
		if(inforResult.getCode() != 10000){
			return  Result.error(CodeMsg.SERVER_ERROR.fillArgs("调用党章申请单服务端异常： "+inforResult.getMsg()));
		}
		if( null == inforResult.getData() ){
			return  Result.error(CodeMsg.NOT_FOUND);
		}
		//封装数据对象
		BusinessData businessData = new BusinessData();
		CcmsPartySealVO info = inforResult.getData();

		// 基础信息
		FormCanvasData business  = new FormCanvasData();
		business.setName("党章申请单");
		business.add("组织",info.getOrgName());
		business.add("申请人",info.getUserName());
		business.add("用章日期",DateTools.dateToString( info.getSealDate(),"yyyy-MM-dd"));
		business.add("用印数量",info.getCount()== null ? "" : info.getCount()+"");
		business.add("类型",info.getTypeName());
		business.add("申请单号",info.getSealCode());
		business.add("用途说明",info.getDescription());
		businessData.addFormCanvasData(business);
		/**
		 * 相关附件  暂未实现
		 */
		TableCanvasData fileInfo = new TableCanvasData();
		fileInfo.setName("附件列表");
		businessData.setFileInfo(fileInfo);

		// 获取审核信息
		Result<Page<ApprovalHistoryEntity>> historyInfoResult = workflowClient.getApprovalHistory(0, Integer.MAX_VALUE, Long.valueOf(info.getProcessInstId()));
		if(historyInfoResult.getCode() != 10000){
			return  Result.error(CodeMsg.SERVER_ERROR.fillArgs("调用工作流获取审批历史服务端异常： "+historyInfoResult.getMsg()));
		}
		//封装审核信息
		this.buildApprovalRecords(businessData,historyInfoResult);

		// 封装审核按钮
		this.buildButtonInfo(businessData);

		// 返回信息
		DictionaryCanvasData resultInfo = new DictionaryCanvasData();
		businessData.setResultInfo(resultInfo);

		return Result.success(businessData);
	}

	/**
	 *  构建   固定资产申请单  详情
	 * @param foreignTaskParam
	 * @return
	 */
	private Result<BusinessData> buildImEmpFaData(ForeignTaskParam foreignTaskParam)throws Exception {
		Result<CcmsImEmpFaVo> inforResult = ccmsImEmpFaClient.findCapital(foreignTaskParam.getBusinessId());
		if(inforResult.getCode() != 10000){
			return  Result.error(CodeMsg.SERVER_ERROR.fillArgs("调用固定资产申请单服务端异常： "+inforResult.getMsg()));
		}
		if( null == inforResult.getData() ){
			return  Result.error(CodeMsg.NOT_FOUND);
		}
		//封装数据对象
		BusinessData businessData = new BusinessData();
		CcmsImEmpFaVo info = inforResult.getData();
		// 基础信息
		FormCanvasData business  = new FormCanvasData();
		business.setName("固定资产申请单");
		//business.add("固定资产申请单ID",info.getEmpFaId());
		business.add("组织",info.getOrgName());
		business.add("资产编码",info.getEmpFaCode());
		business.add("资产分类",info.getFaCatName());
		business.add("申请理由",info.getFaApplyDesc());
		businessData.addFormCanvasData(business);
		/**
		 * 相关附件  暂未实现
		 */
		TableCanvasData fileInfo = new TableCanvasData();
		fileInfo.setName("附件列表");
		businessData.setFileInfo(fileInfo);

		// 获取审核信息
		Result<Page<ApprovalHistoryEntity>> historyInfoResult = workflowClient.getApprovalHistory(0, Integer.MAX_VALUE, Long.valueOf(info.getProcessInstId()));
		if(historyInfoResult.getCode() != 10000){
			return  Result.error(CodeMsg.SERVER_ERROR.fillArgs("调用工作流获取审批历史服务端异常： "+historyInfoResult.getMsg()));
		}
		//封装审核信息
		this.buildApprovalRecords(businessData,historyInfoResult);

		// 封装审核按钮
		this.buildButtonInfo(businessData);

		// 返回信息
		DictionaryCanvasData resultInfo = new DictionaryCanvasData();
		businessData.setResultInfo(resultInfo);

		return Result.success(businessData);
	}



	/**
	 * 构建 离职申请单 详情
	 * @param foreignTaskParam
	 * @return
	 */
	private Result<BusinessData> buildHrEmpDimissionData(ForeignTaskParam foreignTaskParam)throws Exception {
		Result<CcmsHrEmpDimissionVo> inforResult = ccmsHrEmpDimissionClient.findDimission(foreignTaskParam.getBusinessId());
		if(inforResult.getCode() != 10000){
			return  Result.error(CodeMsg.SERVER_ERROR.fillArgs("调用离职申请单服务端异常： "+inforResult.getMsg()));
		}
		if( null == inforResult.getData() ){
			return  Result.error(CodeMsg.NOT_FOUND);
		}
		//封装数据对象
		BusinessData businessData = new BusinessData();
		CcmsHrEmpDimissionVo info = inforResult.getData();
		// 基础信息
		FormCanvasData business  = new FormCanvasData();
		business.setName("离职申请单");
		business.add("计划离岗日期",DateTools.dateToString(info.getLeaveDate(),"yyyy-MM-dd"));
		business.add("交接人",info.getSuperName());
		business.add("申请单编码",info.getEmpDimissionCode());
		business.add("离职原因",info.getDimissionMemo());

		business.add("项目文档",info.getPrjDocs());
		business.add("技术文档",info.getTecDocs());
		business.add("业务往来资料",info.getBizDocs());
		business.add("企业内部文件",info.getEnterpriseFiles());
		business.add("其他",info.getHandover());


	/*
	    business.add("员工离职交接单ID",info.getEmpDimissionId());
		business.add("员工ID",info.getEmpId()+"");
		business.add("员工编码",info.getEmpCode());
		business.add("员工姓名",info.getEmpName());
		business.add("工作交接人ID",info.getSuperUsrId()+"");
		business.add("办公室钥匙交接情况",info.getOfficeKey());
		business.add("办公用品交接情况",info.getOfficeItems());
		business.add("个人借款归还情况",info.getLendCostMemo());
		business.add("培训合同期未满的培训经费归还情况",info.getTrainingCostMemo());
		business.add("其他款项归还情况",info.getOtherCostMemo());
		business.add("是否有报销单的单据未支付",info.getExistsNotPayAmt());
		business.add("离职证明开具情况",info.getFireReferenz());
		business.add("其他事项说明",info.getOtherMemo());
		business.add("审批状态",info.getAuditStatus());
		business.add("当前审批人",info.getAuditUsers());
		business.add("流程实例ID",info.getProcessInstId());*/
		businessData.addFormCanvasData(business);
		/**
		 * 相关附件  暂未实现
		 */
		TableCanvasData fileInfo = new TableCanvasData();
		fileInfo.setName("附件列表");
		businessData.setFileInfo(fileInfo);

		// 获取审核信息
		Result<Page<ApprovalHistoryEntity>> historyInfoResult = workflowClient.getApprovalHistory(0, Integer.MAX_VALUE, Long.valueOf(info.getProcessInstId()));
		if(historyInfoResult.getCode() != 10000){
			return  Result.error(CodeMsg.SERVER_ERROR.fillArgs("调用工作流获取审批历史服务端异常： "+historyInfoResult.getMsg()));
		}
		//封装审核信息
		this.buildApprovalRecords(businessData,historyInfoResult);

		// 封装审核按钮
		this.buildButtonInfo(businessData);

		// 返回信息
		DictionaryCanvasData resultInfo = new DictionaryCanvasData();
		businessData.setResultInfo(resultInfo);

		return Result.success(businessData);
	}
	/**
	 * 构建 因公外出申请单 详情
	 * @param foreignTaskParam
	 * @return
	 */
	private Result<BusinessData> buildHrBizAwayData(ForeignTaskParam foreignTaskParam)throws Exception {

		//因公外出申请单 详情
		Result<CcmsHrBizAwayVo> inforResult = ccmsHrBizAwayClient.findBusiness(foreignTaskParam.getBusinessId());
		if(inforResult.getCode() != 10000){
			return  Result.error(CodeMsg.SERVER_ERROR.fillArgs("调用因公外出申请单服务端异常： "+inforResult.getMsg()));
		}
		if( null == inforResult.getData() ){
			return  Result.error(CodeMsg.NOT_FOUND);
		}
		//封装数据对象
		BusinessData businessData = new BusinessData();
		CcmsHrBizAwayVo info = inforResult.getData();
		// 基础信息
		FormCanvasData business  = new FormCanvasData();
		business.setName("因公外出申请单");
		business.add("组织",info.getOrgName());
		//转日期格式   和因公外出申请单Vo 保持一致
		business.add("外出时间", DateTools.dateToString(info.getAwayDate(),"yyyy-MM-dd"));
		business.add("时段",info.getTimeTypeName());
		business.add("地点",info.getAwayPosition());
		business.add("申请单编码",info.getBizAwayCode());
		business.add("事由",info.getAwayDesc());
		business.add("备注",info.getAwayMemo());

		/*business.add("单据ID",info.getBizAwayId());
		business.add("审批状态",info.getAuditStatus());
		business.add("流程实例ID",info.getProcessInstId());
		business.add("组织",info.getOrgName());
		business.add("组织",info.getOrgId()+"");
		business.add("员工名称",info.getEmpName());
		business.add("申请日期",info.getCreationDate());
		business.add("公出时段ID",info.getTimeTypeId());
		business.add("当前审批人",info.getAuditUsers());*/
		businessData.addFormCanvasData(business);

		/**
		 * 相关附件  暂未实现
		 */
		TableCanvasData fileInfo = new TableCanvasData();
		fileInfo.setName("附件列表");
		businessData.setFileInfo(fileInfo);

		// 获取审核信息
		Result<Page<ApprovalHistoryEntity>> historyInfoResult = workflowClient.getApprovalHistory(0, Integer.MAX_VALUE, Long.valueOf(info.getProcessInstId()));
		if(historyInfoResult.getCode() != 10000){
			return  Result.error(CodeMsg.SERVER_ERROR.fillArgs("调用工作流获取审批历史服务端异常： "+historyInfoResult.getMsg()));
		}
		//封装审核信息
		this.buildApprovalRecords(businessData,historyInfoResult);

		// 封装审核按钮
		this.buildButtonInfo(businessData);

		// 返回信息
		DictionaryCanvasData resultInfo = new DictionaryCanvasData();
		businessData.setResultInfo(resultInfo);

		return Result.success(businessData);
	}

	/**
	 * 构建审核历史信息
	 */
	private  void	buildApprovalRecords(BusinessData businessData,Result<Page<ApprovalHistoryEntity>> historyInfoResult)throws Exception{
		TableCanvasData approvalRecords = new TableCanvasData();
		approvalRecords.setName("审批记录");
		List<ApprovalHistoryEntity>  historyList = historyInfoResult.getData().getRecords();
		if(CollectionUtils.isNotEmpty(historyList)){
			for(int i =0 ;i<historyList.size();i++){
				ApprovalHistoryEntity entity = historyList.get(i);
				RecordData advise = new RecordData();
				advise.add("opinion","审核意见",entity.getApprovalOpinion());
				advise.add("handler","审核人姓名",entity.getActivityUserName());
				advise.add("handlerId","审核人ID",entity.getActivityUser()== null ? "" : entity.getActivityUser()+"");
				advise.add("handlerDate","审核时间", DateTools.dateToString(entity.getStartDate(),"yyyy-MM-dd HH:mm:ss"));
				advise.add("activityName","审核环节",entity.getActivityName());
				advise.add("handlerStatus","审批结果",entity.getOpcodeName());
				approvalRecords.add(advise);
			}
		}
		businessData.setApprovalRecords(approvalRecords);
	}
	/**
	 * 构建审核按钮
	 */
	private  void	buildButtonInfo(BusinessData businessData){
		DictionaryCanvasData buttonInfo = new DictionaryCanvasData();
		buttonInfo.add("同意","1000");
		buttonInfo.add("驳回","1001");
		businessData.setButtonInfo(buttonInfo);
  }

}
